package com.pan.alg.leecode;




import java.util.Stack;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2022/1/18
 */
public class RevertStr {

    /**
     * 反转字符串
     * @param str string字符串
     * @return string字符串
     */
    public String solve (String str) {

        if(null==str||""==str||str.length()==1){
            return str;
        }

        Stack<Character> stack = new Stack();
        // write code here
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            stack.push(aChar);
        }
        StringBuilder revertSb = new StringBuilder();
        while (!stack.empty()){
            revertSb.append(stack.pop());
        }
        revertSb.reverse();
        return revertSb.toString();
    }

    public static void main(String[] args) {

    }
}
